#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>

int main()
{
	int pid,status,pid_child;
	int ret_val;
	
	pid = fork();
	if(pid == -1 ) 
	{
		perror("fork_error:");
		exit(EXIT_FAILURE);
	}
	else if(pid != 0) 
	{
		sleep(1);
		printf("\nIn the PARENT process\n");
		printf("PARENT: My Child PID is %d \n",pid);
		printf("PARENT: My PID is %d \n",getpid());		
		
		/* Parent process */
		waitpid(-1,&status,0);
		if(!(WIFEXITED(status)) )
			printf("Child %d NOT exited properly\n",pid);
	}
	else
	{
		/* Child porcess */
		printf("\nIn the CHILD process\n");
		printf("CHILD: My PID is %d \n",getpid());
		printf("CHILD: My Parent PID is %d \n",getppid());		
	}
	
	return 0;
}
